package me.zhengjie.modules.weixin.message.reply;


import me.zhengjie.modules.weixin.enums.WeChatMsgTypeEnum;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 被动回复图文消息
 */
public class ReplyNewsMessage extends AbstractReplyMessage {

    public ReplyNewsMessage() {
        super();
        setMsgType(WeChatMsgTypeEnum.news.name());
    }

    private Integer ArticleCount;

    private List<NewsMessage> Articles = new ArrayList<>();

    public Integer getArticleCount() {
        return ArticleCount;
    }

    public void setArticleCount(Integer articleCount) {
        ArticleCount = articleCount;
    }

    public List<NewsMessage> getArticles() {
        return Articles;
    }

    public void setArticles(List<NewsMessage> articles) {
        Articles = articles;
    }

    public static class NewsMessage {

        private String Title;

        private String Description;

        private String PicUrl;

        private String Url;

        public String getTitle() {
            return Title;
        }

        public void setTitle(String title) {
            Title = title;
        }

        public String getDescription() {
            return Description;
        }

        public void setDescription(String description) {
            Description = description;
        }

        public String getPicUrl() {
            return PicUrl;
        }

        public void setPicUrl(String picUrl) {
            PicUrl = picUrl;
        }

        public String getUrl() {
            return Url;
        }

        public void setUrl(String url) {
            Url = url;
        }
    }

    @Override
    public String toXML() {
        getXStream().alias("item", NewsMessage.class);
        return super.toXML();
    }

    @Override
    public boolean isValidReply() {
        return null != ArticleCount && ArticleCount >= 1 && CollectionUtils.isNotEmpty(Articles);
    }
}
